<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 个人研发管理原型</title>
    <link rel="stylesheet" href="../libs/layui/css/layui.css">
    <style>
        /* 居中容器 */
        .login-container{
            width: 360px;
            margin: 80px auto;
            padding: 30px 30px 20px;
            background: #fff;
            box-shadow: 0 2px 10px rgba(0,0,0,.08);
            border-radius: 4px;
        }
        .login-title{
            text-align: center;
            font-size: 18px;
            margin-bottom: 20px;
            color: #333;
        }
        body{ background-color: #f2f2f2; }
    </style>
</head>
<body>

    <div class="login-container">
        <div class="login-title">个人研发管理原型 - 登录</div>

        <form class="layui-form" id="login-form" lay-filter="loginForm">
            <div class="layui-form-item">
                <label class="layui-form-label">账号</label>
                <div class="layui-input-block">
                    <input type="text" name="username" required lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="loginBtn">登录</button>
                </div>
            </div>
        </form>
    </div>

    <script src="../libs/layui/layui.js"></script>
    <script>
    // 使用 Layui 规范的模块加载与表单验证
    layui.use(['form', 'layer'], function(){
        var form = layui.form;
        var layer = layui.layer;

        // 自定义校验规则（示例，均为必填）
        form.verify({
            required: function(value, item){
                if(!value || value.trim() === ''){
                    return '该项为必填项';
                }
            }
        });

        // 监听提交
        form.on('submit(loginBtn)', function(data){
            var fields = data.field;
            var username = fields.username;
            var password = fields.password;

            // 纯静态校验：只做非空校验，示例：任何非空都视为成功
            if(!username || !password){
                layer.msg('请输入账号和密码',{icon:5});
                return false;
            }

            // 登录成功：为演示写入 localStorage，并跳转到主页面
            try{
                localStorage.setItem('zyuc_logged_in', '1');
                localStorage.setItem('zyuc_user', username);
            }catch(e){
                // 忽略写入错误
            }

            layer.msg('登录成功，正在跳转...', {icon: 1, time: 1000}, function(){
                // 跳转到 uis/index.html
                window.location.href = 'index.html';
            });

            return false; // 阻止表单默认提交
        });
    });
    </script>
</body>
</html>